home *** CD-ROM | disk | FTP | other *** search
/ Essentials of Interactive Physiology / Essentials of Interactive Physiology.iso / pc / files / code / shared.js < prev    next >
Encoding:
JavaScript  |  2004-07-26  |  9.3 KB  |  318 lines

  1. // open the sized evaluation window (quiz or test)    
  2. function openEvaluationWindow(xsWhich, xsFromWhere){
  3.     var vsPathToEvalFolder = "";
  4.     var macIESuffix = "";
  5.     if (isWinIE()) { macIESuffix = "WinIE" };
  6.     switch (xsFromWhere) {
  7.         case "home":
  8.             vsPathToEvalFolder = "../";
  9.             break;
  10.         case "navbar":
  11.             vsPathToEvalFolder = "../";
  12.             break;
  13.         case "systemtoc":
  14.             vsPathToEvalFolder = "../../../../";
  15.             break;
  16.     }
  17.     
  18.     voNewWin = window.open(vsPathToEvalFolder + "evaluation/" + xsWhich + macIESuffix + ".html", xsWhich, "toolbar=no,location=no,status=no,menubar=yes,scrollbars=no,width=618,height=415,resizable=no");
  19.     voNewWin.focus();
  20. }
  21.  
  22. // Detect if platform is Windows IE.
  23. function isWinIE() {
  24.     var agt = navigator.userAgent.toLowerCase();
  25.     var ie1 = (agt.indexOf("msie") != -1);
  26.     var ie2 = (navigator.appName.toLowerCase().indexOf("microsoft") != -1);
  27.     var mac1 = (agt.indexOf("mac")!=-1);
  28.     var mac2 = (navigator.platform.toLowerCase().indexOf("mac") != -1);
  29.     var isWin = (mac1 || mac2)? false : true;
  30.     var test = ((ie1 || ie2) && (isWin) ? true : false);
  31.     return test;
  32. }
  33.  
  34. //////////// called from media onload
  35. // Set the prevbtns and the pull down in the toolbar and the navbar
  36. function setOtherFramesFromMediaPageOnLoad() {
  37.     if(parent.navbar != null)
  38.         setNextPrevBtns("images/");
  39.  
  40.     // set the pull-down
  41.     if(parent.toolbar.document != null) {
  42.         parent.toolbar.document.theForm.whichPageSelect.selectedIndex=eval(parent.gsPageNum) - 1;
  43.     } 
  44.     
  45.     // set the "return" button
  46.     vsCurValue = getCookie("IPTrail");
  47.     vsTrailLength = getNumberOfItemsFromDelimitedString(vsCurValue, ",");
  48.     
  49.     //alert("The TrailLength is " + vsTrailLength);
  50.     
  51.     // turn on the button if the trail length is 2 or more     
  52.     if(parent.navbar.document.images["return"] != null) {
  53.         if(vsTrailLength >= 3) {
  54.             // turn on the return button
  55.             parent.navbar.document.images["return"].src = "images/return.gif";        
  56.         } else {
  57.             parent.navbar.document.images["return"].src = "images/returngray.gif";                
  58.         }
  59.     }
  60.  
  61. }
  62.  
  63. //////////// called from toolbar
  64. // reload  the media frame with the page num in xsWhere (already a string)
  65. function goToPageInTopicFromToolbar(xsWhere) {
  66.     parent.gsPageNum = xsWhere;
  67.     vsNewURL = "../../../media.html?" + parent.gsSystem + "/" + parent.gsTopic + "/" + parent.gsPageNum;
  68.     parent.content.location = vsNewURL;
  69.     //alert("parent.gsPageNum = "+ xsWhere);        //only called when toolbar is used
  70. }
  71.  
  72.  
  73. //////////// called from navbar
  74. // reload reload the media frame with the page num + xiWhere (which could be minus)
  75. function goToPageInTopicFromNavbar(xiWhere) {
  76.     viCurPage = eval(parent.gsPageNum);
  77.     viNewPage = viCurPage + xiWhere;
  78.     viNumPagesInTopic = eval(parent.gsNumPagesInTopic);
  79.     
  80.     if(viNewPage > 0 && viNewPage <= viNumPagesInTopic) {
  81.         parent.gsPageNum =  padNumToXDigits(String(viNewPage), 2);
  82.         vsNewURL = "media.html?" + parent.gsSystem + "/" + parent.gsTopic + "/" + parent.gsPageNum;
  83.         parent.content.location = vsNewURL;
  84.         //alert("parent.gsPageNum = "+ parent.gsPageNum);  //only called from prev & next buttons
  85.     }
  86. }
  87.  
  88. // reloads and takes off a trail for the cookie
  89. function handleReplayBtnClick() {
  90.     parent.content.location.reload();
  91.     
  92.     // strip off the last value, since we are about to add it back on
  93.      vsCookieValue = getCookie("IPTrail");
  94.  
  95.     // take another off since the page you're going to will add itself to the cookie
  96.      vsStrippedCookie = stripLastItemFromDelimitedString(vsCookieValue, ",");
  97.      
  98.      // reset the cookie with the last item off
  99.      setCookie("IPTrail", vsStrippedCookie);
  100. }
  101.  
  102. // NOT USED ANYMORE
  103. function writeTopicTocBtnHTML() {
  104.     vsSystem = parent.gsSystem;
  105.     document.write("    <a href='javascript:goToSpecificSystemTOC();'><img src='images/" +
  106.                     vsSystem + "toc.gif' border='0'></a>");
  107. }
  108.  
  109. // reload the top with the system TOC (eg. respiratory/index.html)
  110. function goToSpecificSystemTOC() {
  111.     vsNewURL = "systems/" + parent.gsSystem + "/index.html";
  112.     top.location = vsNewURL;
  113. }
  114.  
  115. // reload the whole frameset with new pages
  116. function goToQuizOrTopic() {
  117.     if(topicIsQuizP(parent.gsTopic) == true) {
  118.         vsTopic = getTopicNameFromQuizName(parent.gsTopic);
  119.         vsNewURL = "buildframes.html?" + parent.gsSystem + "/" + vsTopic + "/01"            
  120.         top.location = vsNewURL;
  121.     } else {
  122.         // check if there is a quiz for this topic
  123.         switch(parent.gsTopic) {
  124.             case "heartrev":
  125.             case "vsslrevw":
  126.             case "orient":
  127.             case "overview":
  128.                 alert("Sorry. No quiz exists for this topic.");
  129.                 break;
  130.             default:
  131.                 vsNewURL = "buildframes.html?" + parent.gsSystem + "/" + parent.gsTopic + "q" + "/01";
  132.                 top.location = vsNewURL;
  133.         }
  134.     }
  135.     
  136.  
  137. }
  138.  
  139. // write the html for the quiz btn (and set the link)
  140. function writeToQuizOrToTopicBtnHTML() {
  141.     if(topicIsQuizP(parent.gsTopic) == true) {
  142.         vsBtnSrc = "totopics";
  143.         vsAltTag = "To Topic";
  144.     } else {
  145.         vsBtnSrc = "toquiz";
  146.         vsAltTag = "To Quiz";
  147.     }
  148.  
  149.         switch(parent.gsTopic) {
  150.             case "heartrev":
  151.             case "vsslrevw":
  152.             case "orient":
  153.             case "overview":
  154.             
  155.             case "biosec":
  156.             case "acthorm":
  157.             case "endorient":
  158.             case "hormoneimb":
  159.             case "hypoaxis":
  160.                 document.write("<img src='images/toquizgray.gif' ALT=''>");
  161.                 break;
  162.             default:
  163.                 document.write("    <a href='javascript:goToQuizOrTopic();'><img src='images/" +
  164.                         vsBtnSrc + ".gif' border='0' ALT='" + vsAltTag + "'></a>");
  165.         }
  166.         
  167. }
  168.  
  169. // strip the q off the end
  170. function getTopicNameFromQuizName(xsQuizName) {
  171.     vsTopicName = xsQuizName.substring(0,xsQuizName.length - 1);
  172.     
  173.     return vsTopicName;
  174. }
  175.  
  176. // see if q is the last letter of the topic. If so, Quiz
  177. function topicIsQuizP(xsTopic) {
  178.     vsLastLetter = xsTopic.substring(xsTopic.length - 1, xsTopic.length);
  179.     
  180.     if(vsLastLetter == "q") 
  181.         vbIsQuiz = true;
  182.     else
  183.         vbIsQuiz = false;
  184.  
  185.     return vbIsQuiz;
  186. }
  187.  
  188.  
  189. /////////// called from media.html onload (setOtherFramesFromMediaPageOnLoad)
  190. // set the grayed out state and link of the next and prev btns
  191. function setNextPrevBtns(vsImagesFolderPath) {
  192.     var vsPrevBtnSrc;
  193.     var vsNextBtnSrc;
  194.     var vsCurPageNum = parent.gsPageNum;
  195.     var vsNumPagesInTopic = parent.gsNumPagesInTopic;
  196.     
  197.     // set prev btn
  198.     if(vsCurPageNum == "01") {
  199.         vsPrevBtnSrc = vsImagesFolderPath + "prevgray.gif";
  200.     } else {
  201.         vsPrevBtnSrc = vsImagesFolderPath + "prevup.gif";
  202.     }
  203.     
  204.     // set next btn
  205.     if(vsCurPageNum == vsNumPagesInTopic) {
  206.         vsNextBtnSrc = vsImagesFolderPath + "nextgray.gif";
  207.     } else {
  208.         vsNextBtnSrc = vsImagesFolderPath + "nextup.gif";
  209.     }
  210.  
  211.     if(parent.navbar.document.images["prevBtn"] != null &&
  212.        parent.navbar.document.images["nextBtn"] != null) {
  213.         parent.navbar.document.images["prevBtn"].src = vsPrevBtnSrc;
  214.         parent.navbar.document.images["nextBtn"].src = vsNextBtnSrc;
  215.     }
  216. }
  217.  
  218. // Radio Btn Without Rollover
  219. function sndBtnClick(xsWhich, xsImagePath) {
  220.     if(xsWhich!=selectedItem){
  221.         // set some variables. 
  222.         vsOldSelectedItem = selectedItem;
  223.         selectedItem      = "none" // needed because "home" on is not the "roll" state. 
  224.     
  225.         // turn the new one on
  226.         changeImages(xsWhich, xsImagePath + xsWhich + "down.gif");
  227.  
  228.         // turn the old one off
  229.         changeImages(vsOldSelectedItem, xsImagePath + vsOldSelectedItem + "up.gif");
  230.  
  231.         selectedItem = xsWhich;
  232.         
  233.         if(selectedItem=="yesnarr") {
  234.             setIPSndCookie("true");
  235.             if(window.location.href.indexOf("navbar")!=-1) {
  236.                 parent.gsNarrationOn = "narr"; // yup, string needed
  237.                 if(!topicIsQuizP(parent.gsTopic)) {
  238.                     goToPageInTopicFromNavbar(0);
  239.                 }
  240.             }
  241.         } else {
  242.             setIPSndCookie("false");
  243.             if(window.location.href.indexOf("navbar")!=-1) {
  244.                 parent.gsNarrationOn = ""; // yup, string needed
  245.                 if(!topicIsQuizP(parent.gsTopic)) {
  246.                     goToPageInTopicFromNavbar(0);
  247.                 }
  248.             }
  249.         }
  250.     }    
  251. }
  252.  
  253. ///////////////////////////////////
  254. // SHARED
  255. // declares a new image
  256. function newImage(xsSrc) {
  257.     if (document.images) {
  258.         voTheImage = new Image();
  259.         voTheImage.src = xsSrc;
  260.         return voTheImage;
  261.     }
  262. }
  263.  
  264. // change the image xsImageName to the xsImageSrc
  265. function changeImages(xsImageName, xsImageSrc) {
  266.     if (document.images && (preloadFlag == true)) {
  267.         if(xsImageName != selectedItem && xsImageName!="none") {
  268.             document.images[xsImageName].src = xsImageSrc;
  269.         }
  270.     }
  271. }
  272.  
  273. function preloadImages() {
  274.     if(document.images){
  275.         //just used for preloading
  276.         newImage("images/nonarrup.gif");
  277.         newImage("images/nonarrdown.gif");
  278.         newImage("images/yesnarrdown.gif");
  279.         newImage("images/yesnarrup.gif");
  280.         preloadFlag = true;
  281.     }
  282. }
  283.  
  284. /////////////////////////////////////
  285. // used in navbar.html and each topic menu - systems/systems/<system>/html/to.chtml
  286. function writeNarrationBtnHTML(xsImagePath) {
  287.     vsNarrationOn = narrationOnP(); 
  288.     
  289.     // if no cookie was previously set, set it to true
  290.     if(vsNarrationOn==null) {
  291.         setIPSndCookie("true");
  292.         vsNarrationOn = "true"; // yup, string.
  293.     } 
  294.  
  295.     // set the buttons by the value of vsNarration
  296.     if(vsNarrationOn=="true") {
  297.         vsYesBtnState = "down";
  298.         vsNoBtnState = "up";
  299.         selectedItem = "yesnarr";
  300.     } else {
  301.         vsYesBtnState = "up";
  302.         vsNoBtnState = "down";
  303.         selectedItem = "nonarr";
  304.     }    
  305.         
  306.     document.write("<nobr><A href='#' onclick='sndBtnClick(\"yesnarr\",\"" + xsImagePath + "\"); return false;'><IMG SRC='" + xsImagePath + "yesnarr" + vsYesBtnState + ".gif' name='yesnarr' ALT='Narration On' border='0'></a>");
  307.     document.write("<A href='#' onclick='sndBtnClick(\"nonarr\",\"" + xsImagePath + "\"); return false;'><IMG SRC='" + xsImagePath + "nonarr" + vsNoBtnState + ".gif' name='nonarr' ALT='Narration Off' border='0'></a></nobr>");
  308. }
  309.  
  310.  
  311. ////////////////////
  312. // Used in glossary
  313. function glossaryDone() {
  314.     vsNewURL = "../systems/media.html?" + top.gsSystem + "/" + top.gsTopic + "/" + top.gsPageNum;
  315.     
  316.     top.content.location = vsNewURL;
  317. }
  318.